using NodeCanvas.Variables;
using UnityEngine;

namespace NodeCanvas.Actions
{
	[Name("Get Component")]
	[Category("GameObject")]
	[AgentType(typeof(Transform))]
	public class GetComponentFromAgent : ActionTask
	{
		[RequiredField]
		public string TypeToGet = "Transform";

		public BBComponent saveAs = new BBComponent
		{
			blackboardOnly = true
		};

		protected override string info
		{
			get
			{
				return "Get '" + TypeToGet + "' as " + saveAs;
			}
		}

		protected override void OnExecute()
		{
			Component component = base.agent.GetComponent(TypeToGet);
			saveAs.value = component;
			if (component != null)
			{
				EndAction(true);
				return;
			}
			Debug.LogWarning("No Component named '" + TypeToGet + "' found on agent. Does a Type with such name exist?");
			EndAction(false);
		}
	}
}
